package com.btshop.goods.controller;
import com.btshop.goods.pojo.Para;
import com.btshop.goods.service.ParaService;
import com.github.pagehelper.PageInfo;
import com.util.Result;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName: ParaController
 * @description: Para 控制层接口定义类
 * @author: 李东
 * @Date: 2020-7-20
 */
@Api(value = "ParaController")
@Slf4j
@RestController
@RequestMapping("/para")
@CrossOrigin
public class ParaController {

    @Autowired
    private ParaService paraService;

    /**
     * 根据商品分类id查询参数
     * @param categoryId
     * @return
     */
    @ApiOperation(value = "Para根据商品分类id查询参数",notes = "根据商品分类id查询参数",tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "categoryId", value = "分类id", required = true, dataType = "Long")
    })
    @GetMapping(value = "/category/{categoryId}" )
    public Result<List<Para>> findByCategoryId(@PathVariable("categoryId")Long categoryId){
        List<Para> paras = paraService.findByCategoryId(categoryId);
        return Result.buildSuccess("根据商品分类id查询参数！",paras);
    }

    /***
     * Para分页条件搜索实现
     * @param para
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "Para条件分页查询",notes = "分页条件查询Para方法详情",tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "Para对象",value = "传入JSON数据",required = false) Para para, @PathVariable  int page, @PathVariable  int size){
        log.info("ParaController findPage params , para : {} , page : {} , size : {}",para,page,size);
        //调用ParaService实现分页条件查询Para
        PageInfo<Para> pageInfo = paraService.findPage(para, page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * Para分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "Para分页查询",notes = "分页查询Para方法详情",tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        log.info("ParaController findPage params , page : {} , size : {}",page,size);
        //调用ParaService实现分页查询Para
        PageInfo<Para> pageInfo = paraService.findPage(page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param para
     * @return
     */
    @ApiOperation(value = "Para条件查询",notes = "条件查询Para方法详情",tags = {"ParaController"})
    @PostMapping(value = "/search" )
    public Result<List<Para>> findList(@RequestBody(required = false) @ApiParam(name = "Para对象",value = "传入JSON数据",required = false) Para para){
        log.info("ParaController findList params , para : {} ",para);
        //调用ParaService实现条件查询Para
        List<Para> list = paraService.findList(para);
        return Result.buildSuccess("查询成功！", list);
    }

    /***
     * 根据主键删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "Para根据主键id删除",notes = "根据主键删除Para方法详情",tags = {"ParaController"})
    @ApiImplicitParams({
                @ApiImplicitParam(paramType = "path", name ="id", value = "主键", required = true, dataType = "Long")
    })
    @DeleteMapping(value = "/{id}")
    public Result delete(@PathVariable("id") Long id){
        log.info("ParaController delete params ,   id : {}   ",id);
        //调用ParaService实现根据主键删除
        paraService.delete(id);
        return Result.buildSuccess("删除成功！");
    }

    /***
     * 修改Para数据
     * @param para
     * @param id
     * @return
     */
    @ApiOperation(value = "Para根据id修改",notes = "根据ID修改Para方法详情",tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name ="id", value = "主键", required = true, dataType = "Long")
     })
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "Para对象",value = "传入JSON数据",required = false) Para para,@PathVariable("id") Long id){
        log.info("ParaController update params ,  para : {},  id : {}   ",para,id);
        //设置主键值
        para.setId(id);
        //调用ParaService实现修改Para
        paraService.update(para);
        return Result.buildSuccess("修改成功！");
    }

    /***
     * 新增Para数据
     * @param para
     * @return
     */
    @ApiOperation(value = "Para添加",notes = "添加Para方法详情",tags = {"ParaController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "Para对象",value = "传入JSON数据",required = true) Para para){
        log.info("ParaController add params , para : {}",para);
        //调用ParaService实现添加Para
        paraService.add(para);
        return Result.buildSuccess("添加成功！");
    }

    /***
     * 根据ID查询Para数据
     * @param id
     * @return
     */
    @ApiOperation(value = "Para根据id查询",notes = "根据ID查询Para方法详情",tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name ="id", value = "主键", required = true, dataType = "Long")
            })
    @GetMapping("/{id}")
    public Result<Para> findById(@PathVariable("id") Long id){
        log.info("ParaController findById params ,   id : {}   ",id);
        //调用ParaService实现根据主键查询Para
        Para para = paraService.findById(id);
        return Result.buildSuccess("查询成功！",para);
    }

    /***
     * 查询Para全部数据
     * @return
     */
    @ApiOperation(value = "查询所有Para",notes = "查询所Para有方法详情",tags = {"ParaController"})
    @GetMapping
    public Result<List<Para>> findAll(){
        //调用ParaService实现查询所有Para
        List<Para> list = paraService.findAll();
        return Result.buildSuccess("查询成功！",list);
    }
}
